using System.Configuration;
using System.Web.Mvc;
using Blog.Core.Entities;
using Blog.Infrastructure.Configuration;
using Blog.Infrastructure.Configuration.Blog.Infrastructure.Config;
using Blog.Infrastructure.DataAcces.Repositories.Abstractisations;
using Blog.Infrastructure.DataAcces.Repositories.Implementaions;
using Blog.Infrastructure.DataAcces.Services.Abstractisations;
using Blog.Infrastructure.DataAcces.Services.Implementations;
using Castle.Components.DictionaryAdapter;
using NHibernate;
using StructureMap;

namespace Blog.Presentation.StructureMap
{
    public static class Bootstrapper
    {
        public static void Init()
        {
            ObjectFactory.Initialize(x => x.Scan(scanner =>
            {

                scanner.AddAllTypesOf<Controller>();
                x.For<ISessionFactory>().Singleton().Use(NHibernateConfigurator.MsSqlCeSessionFactory());

                x.For<IRepository<Article>>().Use<Repository<Article>>();
                x.For<IArticleRepository>().Use<ArticleRepository>();
                x.For<IUserRepository>().Use<UserRepository>();
                
                x.For<IAuthenticationService>().Singleton().Use<FormsAuthenticationService>();
                x.For<IMembershipService>().Singleton().Use<MembershipService>();
                x.For<IArticleService>().Use<ArticleService>();

                x.For<ISettings>().Singleton().Add(
                    new DictionaryAdapterFactory().GetAdapter<ISettings>(ConfigurationManager.AppSettings));

            }));
        }
    }
}